package com.game.modular.game.act.cultivate;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.game.comment.core.ResponseResult;
import com.game.comment.util.JwtUtils;
import com.game.modular.game.act.cultivate.vo.CultivateVo;
import com.game.modular.game.playerAssets.domain.PlayerHero;
import com.game.modular.game.playerAssets.service.PlayerHeroServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "玩家武将")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/playerHeroAct")
public class PlayerHeroAction {
    @Resource
    private PlayerHeroServiceImpl playerHeroService;


    @ApiOperation("获取所有自己的武将")
    @PostMapping("/list")
    public ResponseResult<List<PlayerHero>> list(@RequestHeader String token) {
        return ResponseResult.success(playerHeroService.list(JwtUtils.getPlayerId(token)));
    }

    @ApiOperation("升星{\"heroId\": 0}")
    @PostMapping("/upgrade")
    public ResponseResult<PlayerHero> upgrade(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.upgrade param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.upgrade(
                playerId, param.getHeroId())
        );
    }

    @ApiOperation("升级")
    @PostMapping("/levelUp")
    public ResponseResult<PlayerHero> levelUp(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.levelUp param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.levelUp(
                playerId, param.getHeroId(), param.getCorePropId(), param.getCorePropNum())
        );
    }

    @ApiOperation("穿戴装备")
    @PostMapping("/wearEquipment")
    public ResponseResult<PlayerHero> wearEquipment(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.equip param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.wearEquipment(
                playerId, param.getCoreHeroId(), param.getPlayerBagId()
        ));
    }

    @ApiOperation("卸载装备")
    @PostMapping("/unloadEquipment")
    public ResponseResult<PlayerHero> unloadEquipment(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.equip param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.unloadEquipment(
                playerId, param.getCoreHeroId(), param.getPlayerBagId()
        ));
    }

    @ApiOperation("穿戴技能")
    @PostMapping("/wearSkill")
    public ResponseResult<PlayerHero> wearSkill(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.skill param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.wearSkill(
                playerId, param.getHeroId(), param.getSkillSlot(), param.getCoreSkillStarId()
        ));
    }

    @ApiOperation("卸载技能")
    @PostMapping("/unloadSkill")
    public ResponseResult<PlayerHero> unloadSkill(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerHeroVo.skill param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(playerHeroService.unloadSkill(
                playerId, param.getHeroId(), param.getSkillSlot(), param.getCoreSkillStarId()
        ));
    }

    @ApiOperation("查询武将")
    @PostMapping("/select")
    public ResponseResult<PlayerHero> eqSelect(
            @RequestBody CultivateVo.PlayerHeroVo.EqSelect param
    ) {
        return ResponseResult.success(
                playerHeroService.getOne(
                        new LambdaQueryWrapper<PlayerHero>().eq(PlayerHero::getId, param.getPlayerHeroId())
                )
        );
    }
}
